/* ---------------------------------------------------------------------------------------------
 *
 *            Capital Alliance Software Confidential Proprietary
 *            (c) Copyright CAS 201{x}, All Rights Reserved
 *                          www.pekall.com
 *
 * ----------------------------------------------------------------------------------------------
 */

package com.elvis.music.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.widget.Toast;

public class SharedPreference {

    private final String PREFILENAME = "android_music";

    private Context nContext;

    private SharedPreferences nSharedPreferences;

    public SharedPreference(Context context) {
        nContext = context;
        nSharedPreferences = context.getSharedPreferences(PREFILENAME, Context.MODE_PRIVATE);
    }

    public void showMessage(String message) {
        Toast.makeText(nContext, message, Toast.LENGTH_SHORT).show();
    }

    public void saveInt(String key, int value) {
        nSharedPreferences.edit().putInt(key, value).commit();
    }

    public void saveString(String key, String value) {
        nSharedPreferences.edit().putString(key, value).commit();
    }

    public int getInt(String key, int... defValue) {
        if (defValue.length > 0)
            return nSharedPreferences.getInt(key, defValue[0]);
        else {
            return nSharedPreferences.getInt(key, 0);
        }
    }

    public String getString(String key, String defValue) {
        return nSharedPreferences.getString(key, defValue);
    }

    public void saveBoolean(String key , boolean defValue){
        nSharedPreferences.edit().putBoolean(key, defValue).commit();
    }
    public boolean getBoolean(String key ){
        return nSharedPreferences.getBoolean(key, true);
    }
}
